﻿@{
    ViewBag.Title = "Register";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using Recaptcha;

<div class="container">
    <div class="row">
        <div class="span6" style="margin-top: 50px;">
            <h4>Đăng kí tài khoản mới</h4>
            <hr />
            @if (!(String.IsNullOrEmpty(ViewBag.MS)))
            {
                <div class="alert alert-error">@ViewBag.MS</div>
            }
            <form class="form-horizontal" action="/Account/Register" method="post" id="reg_form">
                <div class="control-group">
                    <label class="control-label" for="reg_account">Tài khoản</label>
                    <div class="controls">
                        <input type="text" id="reg_account" placeholder="Tài khoản của bạn" name="reg_account" required>
                        <span id="accountStatus" class="help-inline"><font color="red">Tài khoản đã tồn tại</font></span>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="reg_name">Tên hiển thị</label>
                    <div class="controls">
                        <input type="text" id="reg_name" placeholder="Tài khoản của bạn" name="reg_name" required>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="reg_password">Mật khẩu</label>
                    <div class="controls">
                        <input type="password" id="reg_password" placeholder="Mật khẩu" name="reg_password" required>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="reg_email">Email</label>
                    <div class="controls">
                        <input type="email" id="reg_email" placeholder="Địa chỉ email" name="reg_email" required
                            data-validation-email-message="Email không chính xác" />
                        <span id="emailStatus" class="help-inline"><font color="red">Email đã tồn tại</font></span>
                    </div>
                </div>
                <div class="control-group">
                    <center>
                       @Html.Raw(Html.GenerateCaptcha())
                    </center>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <button type="submit" class="btn">Đăng kí</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="span6" style="margin-top: 50px;">
            <h4>Đã có tài khoản? Đăng nhập</h4>
            <hr />
            <form class="form-horizontal" action="/Account/Login" method="post">
                <div class="control-group">
                    <label class="control-label" for="account">Tài khoản</label>
                    <div class="controls">
                        <input type="text" id="account" placeholder="Tài khoản của bạn" name="account">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="password">Mật khẩu</label>
                    <div class="controls">
                        <input type="password" id="password" placeholder="Mật khẩu">
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <button type="submit" class="btn">Đăng nhập</button>
                        <a href="/Account/GetPassword"> Quên mật khẩu?</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="container">
    <h4>Thanh toán</h4>
    <div class="row">
        @Html.Partial("_Payment")
    </div>
</div>

<script>
    $(function () {
        $('#accountStatus').hide();
        $('#emailStatus').hide();
        $('#reg_account').keyup(function () {
            var account = $.trim($('#reg_account').val());
            var urlString = '@Url.Action("CheckExistedAccount", "Account")';
            $.ajax({
                url: urlString,
                type: "POST",
                data: { stringToCheck: account },
                success: function (data) {
                    $('#accountStatus').show();
                    $('#reg_form').submit(function () {
                        return false;
                    });
                },
                error: function (errorCode) {
                    $('#accountStatus').hide();
                }
            });
        });

        $('#reg_email').keyup(function () {
            var account = $.trim($('#reg_email').val());
            var urlString = '@Url.Action("CheckExistedEmail", "Account")';
            $.ajax({
                url: urlString,
                type: "POST",
                data: { stringToCheck: account },
                success: function (data) {
                    $('#emailStatus').show();
                    $('#reg_form').submit(function () {
                        return false;
                    });
                },
                error: function (errorCode) {
                    $('#emailStatus').hide();
                }
            });
         });
    });
</script>